<?php
namespace app\validate;

use think\Validate;

class UserRegister extends Validate
{
    protected $rule = [
        'mobile'      =>  'checkmobile|require',
        'password'       =>  'require|length:6,32',
        'captcha'   =>  'number|require|length:4',
    	'id'   =>  'number|require',
    ];

    protected $message  =   [
        'mobile.mobile' => '请输入正确的手机号',
        'mobile.require' => '手机号不能为空',
        'password.require'   => '密码不能为空',
        'password.length'   => '密码长度为6-16位',
        'captcha.number'  => '验证码为整数',
        'captcha.require'        => '验证码不能为空',
        'captcha.length' => '验证码长度为4位',
    	'id.number'  => '平台为整数',
    	'id.require'        => '平台不能为空',
    ];

    /**
     * @param $value
     * @param $rule
     * @param array $data
     * @return bool|string
     */
    protected function checkmobile($value,$rule,$data=[])
    {
        $search = '/^0?1[3|4|5|6|7|8|9][0-9]\d{8}$/';
        if (preg_match($search,$value)){
            return $rule = true;
        }else{
            return $rule = '请输入正确的手机号';
        }
    }
}